<template>

  <el-dialog :visible="visible" @close="close" title="文件列表">
    <el-table :data="manuscript">
      <el-table-column align="center" label="文件名" prop="originName" />
      <el-table-column align="center" prop="size" label="文件大小">
        <template slot-scope="scope">
          {{ formatSize(scope.row.size) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="上传时间">
        <template slot-scope="scope">
          {{ timestampToDate(scope.row.createTime) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">

        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="dowload(scope.$index, scope.row)"
            v-hasPermi="['order:file:download']">下载</el-button>
          <el-button v-if="status" size="mini" type="text" icon="el-icon-edit" @click="deleteFile(scope.$index, scope.row)"
            v-hasPermi="['order:file:delete']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>

</template>

<script>
import { timestampToDate } from '@/utils/time'
import { downloadFile, download } from '@/utils/dowload.js'
import { deleteManuscript } from '@/api/order/manuscript.js'
import { formatSize } from '@/utils/file'
export default {
  props: {
    manuscript: {
      type: Array,
      default: []
    },

    order: {
      type: Object,
      default: {}
    },

    status: {
      type: Boolean,
      default: true
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    formatSize,
    timestampToDate,
    deleteFile(index, row) {
      this.$confirm('是否确认删除文件名为"' + row.originName + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info"
      }).then((res) => {
        deleteManuscript(row.id, this);
      }).catch(res => {
        this.$message.success("已取消删除");
      })
    },

    dowload(index, row) {
      console.log("row", row, "this.manscripts", this.manuscript);
      // downloadFile(row.file);
      download( row.file, this.order.orderSn + this.order.serviceName+ row.originName);
    },

    close() {
      this.$emit('closeDialog', false)
    },

    confirm() {
      this.$emit('confirm')
    }
  }
}
</script>

<style></style>
